"""搜索路由模块"""
from flask import Blueprint, request, jsonify
from app.utils.decorators import login_required
from app.models.product import Product

bp = Blueprint('search', __name__)

@bp.route('/search', methods=['POST'])
@login_required
def search():
    """搜索商品"""
    try:
        keyword = request.form.get('keyword', '').strip()
        products = Product.search(keyword)
        return jsonify(products)
    except Exception as e:
        return jsonify({'success': False, 'message': f'数据库操作失败: {str(e)}'}), 500

